<?php
class Place_Model_ShardPlaceComment extends Zend_Db_Table{
    protected $_name  = "shard_place_comment";
    protected $_primary = "place_comment_id";
    
    public function getCommentOfPlace($placeId, $page=1){
        
        $registry   = Zend_Registry::getInstance();
        $constant = $registry->constants;
        $PAGING_NUMBER = $constant->PAGING_NUMBER;
        $start = ($page - 1)*$PAGING_NUMBER;
        
        $shardUtils = new My_Utils_ShardUtils();
        $shard1 = $shardUtils->getShard(0);
        $shard2 = $shardUtils->getShard(1);
        
        $queryGetComment = $shard1  ->select()
                                    ->from('shard_place_comment')
                                    ->where('place_id = ?',$placeId)
                                    ->order('comment_time DESC')
                                    ->limit($PAGING_NUMBER, $start);
        $placeCommentList = array();
        $commentShard1 = $shard1->fetchAll($queryGetComment);
        $commentShard2 = $shard2->fetchAll($queryGetComment);
        
        $placeCommentList = array_merge($commentShard1, $commentShard2);
        return $placeCommentList;
                        
    }


    public function saveComment($arrParams){
        $userId = $arrParams['user_id'];
        $normalUtils = new My_Utils_ShardUtils();
        $DB = $normalUtils->getShard($userId);
        $this->_db = $DB;
        parent::_setupDatabaseAdapter();
        
        
        $row =  $this->fetchNew();
        foreach ($arrParams as $key => $value) {
            $row->$key = $value;
        }
        return $row->save();
    }
}
